home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gscssub.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.6 KB  |  115 lines

  1. /* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gscssub.c,v 1.2 2000/09/19 19:00:27 lpd Exp $ */
  20. /* Color space substitution "operators" */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gscssub.h"
  24. #include "gxcspace.h"        /* for st_color_space */
  25. #include "gxdevcli.h"
  26. #include "gzstate.h"
  27.  
  28. /* .setsubstitutecolorspace */
  29. int
  30. gs_setsubstitutecolorspace(gs_state *pgs, gs_color_space_index csi,
  31.                const gs_color_space *pcs)
  32. {
  33.     int index = (int)csi;
  34.     static const uint masks[3] = {
  35.     (1 << gs_color_space_index_DeviceGray) |
  36.       (1 << gs_color_space_index_CIEA),
  37.     (1 << gs_color_space_index_DeviceRGB) |
  38.       (1 << gs_color_space_index_CIEABC) |
  39.       (1 << gs_color_space_index_CIEDEF),
  40.     (1 << gs_color_space_index_DeviceCMYK) |
  41.       (1 << gs_color_space_index_CIEDEFG)
  42.     };
  43.     const gs_color_space *pcs_old;
  44.  
  45.     if (index < 0 || index > 2)
  46.     return_error(gs_error_rangecheck);
  47.     if (pcs) {
  48.     if (!masks[index] & (1 << gs_color_space_get_index(pcs)))
  49.         return_error(gs_error_rangecheck);
  50.     }
  51.     pcs_old = pgs->device_color_spaces.indexed[index];
  52.     if (pcs_old == 0) {
  53.     gs_color_space *pcs_new;
  54.  
  55.     if (pcs == 0 || gs_color_space_get_index(pcs) == csi)
  56.         return 0;
  57.     pcs_new = gs_alloc_struct(pgs->memory, gs_color_space, &st_color_space,
  58.                   "gs_setsubstitutecolorspace");
  59.     if (pcs_new == 0)
  60.         return_error(gs_error_VMerror);
  61.     gs_cspace_init_from(pcs_new, pcs);
  62.     pgs->device_color_spaces.indexed[index] = pcs_new;
  63.     } else {
  64.     gs_cspace_assign(pgs->device_color_spaces.indexed[index],
  65.              (pcs ? pcs :
  66.               pgs->shared->device_color_spaces.indexed[index]));
  67.     }
  68.     return 0;
  69. }
  70.  
  71. /* Possibly-substituted color space accessors. */
  72. const gs_color_space *
  73. gs_current_DeviceGray_space(const gs_state *pgs)
  74. {
  75.     const gs_color_space *pcs;
  76.  
  77.     return (!pgs->device->UseCIEColor ||
  78.         (pcs = pgs->device_color_spaces.named.Gray) == 0 ?
  79.         pgs->shared->device_color_spaces.named.Gray : pcs);
  80. }
  81. const gs_color_space *
  82. gs_current_DeviceRGB_space(const gs_state *pgs)
  83. {
  84.     const gs_color_space *pcs;
  85.  
  86.     return (!pgs->device->UseCIEColor ||
  87.         (pcs = pgs->device_color_spaces.named.RGB) == 0 ?
  88.         pgs->shared->device_color_spaces.named.RGB : pcs);
  89. }
  90. const gs_color_space *
  91. gs_current_DeviceCMYK_space(const gs_state *pgs)
  92. {
  93.     const gs_color_space *pcs;
  94.  
  95.     return (!pgs->device->UseCIEColor ||
  96.         (pcs = pgs->device_color_spaces.named.CMYK) == 0 ?
  97.         pgs->shared->device_color_spaces.named.CMYK : pcs);
  98. }
  99.  
  100. /* .currentsubstitutecolorspace */
  101. const gs_color_space *
  102. gs_currentsubstitutecolorspace(const gs_state *pgs, gs_color_space_index csi)
  103. {
  104.     switch (csi) {
  105.     case gs_color_space_index_DeviceGray:
  106.     return gs_current_DeviceGray_space(pgs);
  107.     case gs_color_space_index_DeviceRGB:
  108.     return gs_current_DeviceRGB_space(pgs);
  109.     case gs_color_space_index_DeviceCMYK:
  110.     return gs_current_DeviceCMYK_space(pgs);
  111.     default:
  112.     return 0;
  113.     }
  114. }
  115.